﻿using System;
using System.Windows;
using Baosight.ZNH.ZMCommon;
using Baosight.Platform.Core;
using Baosight.Platform.Core.UI.Controls;
using Baosight.Platform.Core.UI;
using Microsoft.Practices.Unity;
using Telerik.Windows.Controls;
using System.Collections.Generic;
using Baosight.ZNH.ZMCommon.ChildWindows;
using System.Windows.Controls;
using Telerik.Windows.Controls.GridView;
using Baosight.ZNH.ZMCP.UI.Blocks;
using Baosight.ZNH.ZMCP.UI.PopWindows;
using Baosight.Platform.Core.ServiceModel;

namespace Baosight.ZNH.ZMCP.UI
{
    /// <summary>
    /// 已处理的生产问题
    /// </summary>
    /// Copyright:Baosight Software LTD.co Copyright (c) 2011
    /// Company:上海宝信软件股份有限公司
    /// Author: 张志芳
    /// Version: 1.0
    /// History:
    ///       2011-08-31  张志芳   [创建]
    ///
    public partial class ZMCPB2 : EFViewCmes
    {
        private ProduceProblemBlock problemBlock = new ProduceProblemBlock();
        public ZMCPB2()
        {
            InitializeComponent();
        }

        public override void Initialize(EIInfo initData)
        {
            initData.AddBlock(problemBlock.getProblemOrigin());
            initData.AddBlock(problemBlock.getProblemStatus());
            base.Initialize(initData);
        }

        /// <summary>
        /// 查看
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void HyperlinkButton_Click(object sender, RoutedEventArgs e)
        {
            HyperlinkButton link = sender as HyperlinkButton;
            EIRow row = (link.ParentOfType<GridViewRow>().Item as UIBaseEntity).GetEIRow();
            EIInfo eiInfo = new EIInfo();
            EIBlock eIBlock = new EIBlock("result");
            eIBlock.SetRow(0, row == null ? new EIRow() : row);
            eiInfo.AddBlock(eIBlock);

            base.OnHyperlinkButtonClickPopup(eiInfo, "生产问题-查看", "detail", null, sender, e);
        }

        /// <summary>
        /// 弹出新增修改页面
        /// </summary>
        /// <param name="_eIInfo"></param>
        /// <param name="_title"></param>
        /// <param name="_dialogType"></param>
        /// <param name="_args"></param>
        public override void OpenPopup(EIInfo _eIInfo, string _title, string _dialogType, string _args)
        {
            AddProduceProblem _problem = new AddProduceProblem(_dialogType);//构造一个新的修改页面

            _eIInfo.AddBlock(problemBlock.getProblemOrigin());//传递问题来源block
            _eIInfo.AddBlock(problemBlock.getIsCheck());//传递问题来源block
            _eIInfo.AddBlock(this.EIDataContext.GetBlock("cmes.cp.problemType"));//问题类型 
            _eIInfo.AddBlock(this.EIDataContext.GetBlock("cmes.cp.problemLevel"));//问题级别 
            _eIInfo.AddBlock(this.EIDataContext.GetBlock("cmes.cp.department"));//部门

            _problem.EIDataContext = new Platform.Core.UI.EIDataContext();
            _problem.EIDataContext.Update(_eIInfo);

            CmesWindows _popup = new CmesWindows();//构造一个弹出页面
            _popup.ResizeMode = ResizeMode.NoResize;//设置不能修改窗口大小
            _popup.Header = _title == null ? "" : _title;//设置Title
            _popup.Content = _problem;//让新增页面在弹出窗口显示
            _popup.Closed += new EventHandler<WindowClosedEventArgs>(CmesWindow_Closed);
            _popup.ShowDialog();//模态显示弹出窗口
        }

        /// <summary>
        /// 弹出窗口关闭时执行的方法
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CmesWindow_Closed(object sender, WindowClosedEventArgs e)
        {
            if (e.DialogResult == true)
            {
                //刷新Grid区域
                this.grid.Refresh();
            }

            //按钮生效
            base.TempButtonOpen(true);

            //超链接生效
            if (base.TempHyperlink != null)
            {
                base.TempHyperlink.IsEnabled = true;
                base.TempHyperlink = null;
            }
        }
    }
}
